home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Common / media.bas < prev    next >
BASIC Source File  |  2001-10-08  |  3KB  |  58 lines

  1. Attribute VB_Name = "MediaDir"
  2. Option Explicit
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. '
  5. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  6. '
  7. '  File:       media.bas
  8. '
  9. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  10.  
  11. 'Registry constants
  12. Private Const KEY_READ = 131097
  13. Private Const REG_SZ = 1
  14. Private Const HKEY_LOCAL_MACHINE = &H80000002
  15. 'Registry API's
  16. Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
  17. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  18. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
  19. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  20.  
  21. Public Function FindMediaDir(ByVal sFile As String, Optional ByVal fUseCMedia As Boolean = False) As String
  22.     If Dir$(sFile, vbNormal) <> vbNullString Then 'This file is the current folder
  23.         FindMediaDir = AddDirSep(CurDir)
  24.         Exit Function
  25.     End If
  26.     If fUseCMedia Then
  27.         FindMediaDir = AddDirSep(GetDXSampleFolder) & "media\"
  28.     Else
  29.         FindMediaDir = AddDirSep(GetDXSampleFolder) & "vbsamples\media\"
  30.     End If
  31. End Function
  32.  
  33. Public Function AddDirSep(ByVal sPath As String) As String
  34.     AddDirSep = sPath
  35.     If Right$(sPath, 1) <> "\" Then
  36.         AddDirSep = sPath & "\"
  37.     End If
  38. End Function
  39.  
  40. Public Function GetDXSampleFolder() As String
  41.     Dim lHandle As Long
  42.     Dim lNewHandle As Long, sValue As String
  43.     Dim lNewKey As Long
  44.     
  45.     RegConnectRegistry vbNullString, HKEY_LOCAL_MACHINE, lHandle
  46.     RegOpenKeyEx lHandle, "SOFTWARE\Microsoft\DirectX SDK", 0, KEY_READ, lNewHandle
  47.     sValue = Space$(255)
  48.     RegQueryValueEx lNewHandle, "DX81SDK Samples Path", 0, REG_SZ, sValue, 255
  49.     If sValue <> Space$(255) Then
  50.         sValue = Left$(sValue, InStr(sValue, Chr$(0)) - 1)
  51.     Else
  52.         sValue = vbNullString
  53.     End If
  54.     RegCloseKey lNewHandle
  55.     RegCloseKey lHandle
  56.     GetDXSampleFolder = sValue
  57. End Function
  58.